package com.meijin.spring6.di_xml;

import lombok.Data;

/**
 * @Author meijindeng
 * @Data 2023-09-01 13:32
 * @Description 依赖注入（给属性注入值）的setter 注入和构造器注入实体类
 * @Version 1.0
 */
//@Data包含get/set方法、无参、toString、equals和hash方法
@Data
public class Book {

    private String name;

    private String price;

    public Book() {
        System.out.println("Book的'无'参构造执行了！");
    }

    public Book(String name, String price) {
        System.out.println("Book的'有'参构造执行了！");
        this.name = name;
        this.price = price;
    }

    /**
     * @description 原生方法
     * @author meijindeng
     * @date 2023/9/1 13:35
     */
    public static void main(String[] args) {
        //1、set方法注入
        Book book = new Book();
        book.setName("Java");
        book.setPrice("121.5");
        System.out.println("set方法注入：" + book);
        //2、构造器注入
        Book book1 = new Book("C++", "34.5");
        System.out.println("构造器注入：" + book1);
    }

    public void getBookInfo() {
        System.out.print("名称：" + name + "，" + "价格：" + price);
    }
}
